"use strict";

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  const { router, controller } = app;
  const jwt = app.middleware.jwt(app.config.jwt);

  router.get("/", controller.home.index);
  /**
   *
   */
  router.post("/v2/login", controller.user.login);
  // 获取验证码 genVeriCode
  router.get("/v2/genVeriCode", controller.user.genVeriCode);

  // 登陆
  router.post("/v2/users/loginByPhoneNumber", controller.user.login);
  // 用户信息接口users/getUserInfo
  router.post("/v2/users/getUserInfo", controller.user.getUserInfo);
  router.post(
    "/v2/users/getUserInfo/costom",
    jwt,
    controller.user.getUserInfoCostom
  );
  // 模版库接口： templates
  router.get("/v2/templates", controller.user.templateList);
  // 根据id查询某个模版语句
  router.get("/v2/template/:id", controller.user.template);

  // oss 上传图片接口
  router.post("/v2/utils/upload-img", controller.oss.upload);

  // 保存作品接口
  router.post("/v2/works/:workId", controller.work.saveWork);

  // 发布接口，用来更新模版的isPublic状态1-0 publish
  router.post("/v2/works/publish/:workId", controller.work.publish);
  // 创建作品: works
  router.post("/v2/works", jwt, controller.work.createWork);
  // 通过用户手机号获取作品信息
  router.get("/v2/my-works", jwt, controller.work.getUserWork);

  // 获取当前作品接口,用于前端渲染发布页面 getWork
  router.get("/v2/works/:workId", controller.work.getWork);
  /**
   * ----------------------------------------------
   */
  router.post("/v2/register", controller.home.register);
  router.get("/v2/refreshToken", controller.home.refreshToken);
  router.post("/v2/syncLocalWork", controller.home.syncLocalWork);
  router.post("/v2/addComments", controller.home.addComments);
  router.post("/v2/addPartner", controller.home.addPartner);
  router.get("/v2/getPartner", controller.home.getPartner);
  router.get("/v2/getLocalWorkList", jwt, controller.home.getLocalWorkList);
  router.get("/v2/getComments", controller.home.getComments);
  router.get("/v2/getWorkById", controller.home.getWorkById);

  // 增
  router.post("/api/upload", controller.oss.upload);
  // 删
  router.delete("/api/delete", controller.oss.delete);
  // 查
  router.get("/api/down", controller.oss.download);
};
